#!/usr/bin/env python3
# -*- coding=utf-8 -*-

import os
from utils import Common
from multithreadings import MultiThreading


class ExecRobot(object):
    def __init__(self):
        self.curtime = Common().get_curtime()

    def exec_pybot(self):
        """
        执行pybot
        """
        cmd_list = []
        test_suite, tag_list = Common().getTags(Common().get_para_from_jenkins())
        print(test_suite)
        print(tag_list)

        for tag in tag_list:
            cmd = r"pybot -i {0} -o ./resultDir/result_{2}/output-{0}.xml -l ./resultDir/result_{2}/log-{0}.html -r ./resultDir/result_{2}/report-{0}.html {1}".format(
                tag, test_suite, self.curtime)
            cmd_list.append(cmd)
            print("执行脚本：\n" + cmd)

        MultiThreading.multi_exec(cmd_list)

    def exec_rebot(self):
        """
        执行rebot
        """
        cmd = r"rebot --output ./resultDir/output-{0}.xml -l ./resultDir/log-{0}.html -r ./resultDir/report-{0}.html --merge ./resultDir/result_{0}/output-*.xml".format(
            self.curtime)
        print("合并报告：\n" + cmd)
        os.system(cmd)
        Common().clean_logs()
